using System.Linq;

namespace MirrorMirror
{
    public static class StringExtensions
    {
        public static string GetFrom(this string text, string start)
        {
            var index = text.IndexOf(start);
            return index == -1 ? string.Empty : text.Substring(index + start.Length);
        }

        public static string GetUntil(this string text, params string[] ends)
        {
            var value = text;
            foreach (var end in ends)
            {
                var index = text.IndexOf(end);
                if (index <= -1) continue;

                var tryValue = text.Substring(0, index);
                if (tryValue.Length < value.Length)
                    value = tryValue;
            }
            return value;
        }

        public static string Remove(this string text, string textToRemove)
        {
            return text.Replace(textToRemove, string.Empty);
        }

        public static string FirstMatch(this string text, params string[] options)
        {
            return options.FirstOrDefault(text.Contains);
        }
    }
}